'use strict';

/**
 * 地理对象集合组件
 * @example
 * <CesiumProjectContents
 *  scene={scene}
 *  dataSources={dataSources}
 *  icons={icons}
 *  labels={labels}
 *  polylines={polylines}
 *  cesium3DTilesets={cesium3DTilesets}
 *  czml={czml}
 * />
 */
var CesiumProjectContents = React.createClass({
    displayName: 'CesiumProjectContents',
    componentWillMount: function componentWillMount() {
        /**
         * 图表集合
         * @type {Cesium.BillboardCollection}
         */
        this.billboards = new Cesium.BillboardCollection();
        /**
         * 标签集合
         * @type {Cesium.LabelCollection}
         */
        this.labels = new Cesium.LabelCollection();
        /**
         * 线要素集合
         * @type {Cesium.PolylineCollection}
         */
        this.polylines = new Cesium.PolylineCollection();
        /**
         * 地理实体总集合
         * @type {Array}
         */
        this.primitiveCollections = [this.billboards, this.labels, this.polylines];

        var scene = this.props.scene;
        if (scene) {
            this.primitiveCollections.forEach(function (primitiveCollection) {
                return scene.primitives.add(primitiveCollection);
            });
        }
    },
    componentWillUnmount: function componentWillUnmount() {
        this.primitiveCollections.forEach(function (primitiveCollection) {
            if (!primitiveCollection.isDestroyed()) {
                primitiveCollection.destroy();
            }
        });

        var scene = this.props.scene;

        if (scene && !scene.isDestroyed() && scene.primitives) {
            this.primitiveCollections.forEach(function (primitiveCollection) {
                return scene.primitives.remove(primitiveCollection);
            });
        }
    },
    render: function render() {
        var renderedPolylines = null;
        if (this.props.polylines) {
            var polylines = this.polylines;
            renderedPolylines = this.props.polylines.map(function (polyline, index) {
                return React.createElement(CesiumPolyline, {
                    coords: polyline,
                    polylines: polylines,
                    key: index
                });
            });
        }
        return React.createElement(
            'span',
            null,
            renderedPolylines
        );
    }
});